# 层间散度与精度衰减关系
delta = [0.5, 0.6, 0.7, 0.8, 0.9]
fedprox_decay = [12.3, 15.1, 18.3, 22.7, 26.5]  # FedProx精度衰减率(%)
dhaf_decay = [3.2, 4.1, 5.7, 7.8, 9.4]         # DHA-FL精度衰减率(%)

plt.figure(figsize=(5, 3))
plt.plot(delta, fedprox_decay, 'bo--', label='FedProx')
plt.plot(delta, dhaf_decay, 'rs-', label='DHA-FL')

# 标注关键点
plt.text(0.7, 6.5, f'衰减率: {dhaf_decay[2]}%', 
         ha='center', fontsize=10, bbox=dict(facecolor='white', alpha=0.8))
plt.text(0.7, 19, f'衰减率: {fedprox_decay[2]}%', 
         ha='center', fontsize=10)

plt.xlabel('层间散度 δ', fontsize=12)
plt.ylabel('精度衰减率 (%)', fontsize=12)
# plt.title('Sensitivity to Non-IID Data Distribution', fontsize=14)
plt.legend(prop={'size': 12, 'family': 'SimHei'})
plt.grid(alpha=0.3)
plt.savefig('non_iid_sensitivity.png', bbox_inches='tight')
